import os

def listdir(path, recursive=False):
    """生成器, 递归遍历目录下的所有文件并返回

    Args:
        path (str): 文件夹路径名
        recursive (bool, optional): 是否递归寻找. Defaults to False.

    Yields:
        str: 文件夹下的文件
    """
    files = os.listdir(path)
    for file in files:
        file_path = os.path.join(path, file)

        if os.path.isfile(file_path):
            yield file_path

        elif recursive and os.path.isdir(file_path):
            for f in listdir(file_path, recursive=True):
                yield f

